1767D - Playoff - CodeForces Solution


combinatorics constructive algorithms dp greedy math *1500

Please click on ads to support us..

Python Code:

n = int(input())

st = input()
s = 0
for i in range(n):
    if st[i] == '1':
        s += 1

l = 2 ** s
r = (2 ** n) - (2 ** (n - s) ) + 2

out = ""

for i in range(l, r):
    out += str(i) + " "
print(out)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define en '\n'
#define vec vector
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define in(x,y) (y).find((x))!=(y).end()
#define nin(x,y) (y).find((x))==(y).end()

#ifdef DEBUG
#include "template/debug.h"
#else
#define debug(x...)
#define enhance(x)
#endif 


void solve() {
	int n; cin>>n;
	string s; cin>>s;
	vec<int> pow2(n+1);
	pow2[0]=1;
	int x=0, y=0;
	for(int i=0; i<n; ++i){
		if(s[i]=='1') ++x;
		else ++y;
		pow2[i+1]=2*pow2[i];
	}
	
	if(x==0){
		cout<<1<<en; return;
	}
	if(y==0){
		cout<<pow2[n]<<en; return;
	}
	int a=pow2[x], b=pow2[n]-pow2[y]+1;
	for(int i=a; i<=b; ++i){
		cout<<i<<" ";
	}
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
}


Comments

Submit
0 Comments
More Questions

429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100